package com.koron.css2.clientCenter.impl;

import com.koron.css2.baseConfig.bean.ReadingMeterStatusBean;
import com.koron.css2.baseConfig.mapper.ReadingMeterStatusMapper;
import com.koron.css2.clientCenter.bean.MeterReadingListBean;
import com.koron.css2.clientCenter.mapper.UserInfoMapper;
import com.koron.css2.clientCenter.queryBean.UserChangeQueryBean;
import com.koron.css2.common.dto.AttachmentDto;
import com.koron.css2.common.service.AbstractExportExcel;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.CommonUtils;
import com.koron.css2.serviceManage.utils.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;

import java.util.List;

/**
 * 抄表信息导出
 *
 * @author 廖祥仁
 *
 */
public class MeterReadingExport extends AbstractExportExcel {

	@Override
	public AttachmentDto getAttachment(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		UserChangeQueryBean bean = JsonUtils.objectToPojo(req.getData(), UserChangeQueryBean.class);
		UserInfoMapper mapper = factory.getMapper(UserInfoMapper.class);
		List<MeterReadingListBean> list = mapper.meterReadingList(bean);
		// 获取抄表状态
		ReadingMeterStatusMapper statusMapper = factory.getMapper(ReadingMeterStatusMapper.class);
		List<ReadingMeterStatusBean> statusList = statusMapper.readingMeterStatusList();

//		StaffMapper staffMapper = factory.getMapper(StaffMapper.class);
//		List<StaffBean> staffs = staffMapper.selectList(new StaffQueryBean());
		for (MeterReadingListBean read : list) {//循环遍历抄表状态
			for (ReadingMeterStatusBean status : statusList) {
				if (status.getStatusValue() == read.getStatus()) {
					read.setStatusName(status.getStatusName());
				}
			}

//			if(StringUtils.isNotBlank(read.getMeterReadingStaff())) {
//				for(StaffBean staff:staffs) {
//					if (staff.getCode() != null && staff.getCode().equals(read.getMeterReadingStaffAccount())) {
//						read.setMobile(staff.getMobile());
//					}
//				}
//			}


			//替换换表标记
			if(read.getChangeMeterFlag() == 0){
				read.setChangeMeterFlagName("否");
			}else {
				read.setChangeMeterFlagName("是");
			}
		}
		//返回
		AttachmentDto attachment = new AttachmentDto();
		attachment.setBtlTemplate("MeterReadingExport.btl");
		attachment.setFileTemplate("MeterReadingExport.xlsx");
		attachment.setData(list);
		attachment.setFileType("excel");
		attachment.setFilename("抄表信息" + CommonUtils.getCurrentDate());
		return attachment;
	}
}
